<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'排课列表'),	
);
if($_RQ['op']=='list'){
	$params=array('status'=>1,'storeid'=>$this->store_id);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['area_id'])){
		$params['area_id']=intval($_RQ['area_id']);
		$return['params']['area_id']=$_RQ['area_id'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['groupid'])){
		$params['groupid']=intval($_RQ['groupid']);
		$return['params']['groupid']=$_RQ['groupid'];
	}
	if(!empty($_RQ['workerid'])){
		$params['workerid']=intval($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yiliao_lesson_pai',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['lesson']=pdo_get('jy_yiliao_lesson',array('id'=>$item['lessonid'],'uniacid'=>$_SESSION['uniacid']));
			$item['ontime']=$this->model('lesson')->get_uptime($item['ontime']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'tip'=>'报名科室','list'=>array(
			array('name'=>'lesson.title','title'=>'科室名称','type'=>'string'),
			array('name'=>'area_id','title'=>'所属区域','type'=>'select','options'=>'areas'),
			array('name'=>'storeid','title'=>'所属校区','type'=>'select','options'=>'stores'),
			array('name'=>'lesson.groupid','title'=>'科室类型','type'=>'select','options'=>'groups'),
			array('name'=>'workerid','title'=>'讲师','type'=>'select','options'=>'workers','option_title'=>'name'),
			array('name'=>'ontime','title'=>'上课时间','type'=>'string'),
		),'action'=>array(
		)),
		'search'=>array(
			array('name'=>'area_id','width'=>10,'title'=>'所属区域','type'=>'select','options'=>'areas'),
			array('name'=>'storeid','width'=>10,'title'=>'所属校区','type'=>'select','options'=>'stores'),
			array('name'=>'groupid','width'=>10,'title'=>'科室类型','type'=>'select','options'=>'groups'),
			array('name'=>'workerid','width'=>10,'title'=>'讲师','type'=>'select','options'=>'workers','option_title'=>'name'),
			array('name'=>'title','width'=>10,'title'=>'科室名称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	$return['stores']=pdo_getall('jy_yiliao_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['areas']=pdo_getall('jy_yiliao_area',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['groups']=pdo_getall('jy_yiliao_lesson_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['workers']=pdo_getall('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid']),array('id','name'),'id');
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('status'=>1,'storeid'=>$this->store_id,'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['area_id'])){
		$params['area_id']=intval($_RQ['area_id']);
		$return['params']['area_id']=$_RQ['area_id'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['groupid'])){
		$params['groupid']=intval($_RQ['groupid']);
		$return['params']['groupid']=$_RQ['groupid'];
	}
	if(!empty($_RQ['workerid'])){
		$params['workerid']=intval($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	$lesson=pdo_getall('jy_yiliao_lesson_pai',$params);
	foreach($lesson as &$v){
		$v['starttime']=date('Y-m-d',$v['starttime']);
		$v['endtime']=date('Y-m-d',$v['endtime']);
		$v['storetitle']=pdo_getcolumn('jy_yiliao_store',array('id'=>$v['storeid']),'title');
		$v['storetitle']=$v['storetitle']?:'无';
		$v['areatitle']=pdo_getcolumn('jy_yiliao_area',array('id'=>$v['area_id']),'title');
		$v['grouptitle']=pdo_getcolumn('jy_yiliao_lesson_group',array('id'=>$v['groupid']),'title');
		$v['workertitle']=pdo_getcolumn('jy_yiliao_worker',array('id'=>$v['workerid']),'name');
	}
	$header=array(
		'id'=>'科室ID',
		'title'=>'科室名称',
		'areatitle'=>'所属区域',
		'storetitle'=>'所属校区',
		'grouptitle'=>'科室类型',
		'workertitle'=>'讲师',
		'starttime'=>'开始时间',
		'endtime'=>'结束时间',
	);
	cfc('tools')->export2excel($header,$lesson,'科室表');
}